#include "widget.h"
#include "ui_widget.h"
#include <QPushButton>
#include <QGridLayout>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    // 创建三个按钮
    QPushButton* button1 = new QPushButton("按钮1");
    QPushButton* button2 = new QPushButton("按钮2");
    QPushButton* button3 = new QPushButton("按钮3");
    // 创建网格布局管理器
    QGridLayout* grid = new QGridLayout(this);
    // 添加按钮到网格中
    grid->addWidget(button1, 0,0);
    grid->addWidget(button2, 0,1);
    grid->addWidget(button3, 0,2);
    // 设置列的拉伸系数：此时三个按钮的宽度就会按照 1:1:2 的比例进行拉伸设置
    grid->setColumnStretch(0, 1);
    grid->setColumnStretch(1, 1);
    grid->setColumnStretch(2, 2);
}

Widget::~Widget()
{
    delete ui;
}

